﻿Imports TwitterVB2
Public Class Form1
    Dim tw As New TwitterAPI
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Settings.FirstRun = "" Then
            Form2.Show()
            Form2.Focus()
        End If
        Form2.txtUsername.Text = My.Settings.Username
        Form2.txtPassword.Text = My.Settings.Password
        Form2.txtZip.Text = My.Settings.ZipCode
    End Sub

    Private Sub btnSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSettings.Click
        Form2.Show()
    End Sub

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        If My.Settings.FirstRun = "No" Then
            ' Timer1.Enabled = True
            GetRegion(txtzip.Text)
            GetWeather(txtzip.Text)
            GetForecast(txtzip.Text)
            tw.AuthenticateWith("oh7NBaDDfwrhFR7WqF9w", "VnA7OYXargHBDzoPdZE4aXsvZ7o85lZXwUsUMtcI", My.Settings.OAuthToken, My.Settings.OAuthTokenSecret)
            tw.Update("CURRENT CONDITIONS in " & Label2.Text & " " & lblcc.Text & ". FORECAST-" & lblforecast.Text)
        Else
            Form2.Show()
            MsgBox("You must authorize WeatherTweet to be used with your Twitter Profile.")
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        GetWeather(txtzip.Text)
        GetForecast(txtzip.Text)
    End Sub

#Region "Form Move"
    'Declare the variables
    Dim drag As Boolean
    Dim mousex As Integer
    Dim mousey As Integer

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        drag = True
        mousex = Windows.Forms.Cursor.Position.X - Me.Left
        mousey = Windows.Forms.Cursor.Position.Y - Me.Top
    End Sub
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If drag = True Then
            Me.Top = Windows.Forms.Cursor.Position.Y - mousey
            Me.Left = Windows.Forms.Cursor.Position.X - mousex
        End If
    End Sub
    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        drag = False
    End Sub
#End Region

    Private Sub txtzip_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtzip.KeyUp
        If e.KeyCode = Keys.Enter Then
            Call btnGo_Click(sender, e)
        End If
    End Sub

    Private Sub picClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picClose.Click
        Me.Close()
    End Sub
End Class
